package com.ruoyi.patient.service;


import com.ruoyi.patient.entity.explain.*;
import com.ruoyi.service.domain.ServiceFlag;
import com.ruoyi.service.domain.ServiceRule;
import com.ruoyi.service.mapper.ServiceFlagMapper;
import com.ruoyi.service.mapper.ServiceRuleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

@Component
public class PatientExplainService {


    @Autowired
    private ServiceFlagMapper flagMapper;
    @Autowired
    private ServiceRuleMapper ruleMapper;


    public ExplainRsp getProDetail() {
        ExplainRsp retExplain = new ExplainRsp();

        ServiceIntro serviceIntro = new ServiceIntro();
        //serviceIntro.setContent("打针:由西峰区人民医院专业护士为需要皮下或肌肉注射的患者提供的上门打针的护理服务，不提供相关药物。\n" +
        //        "普通换药:由西峰区人民医院专业护士提供普通伤口或术后的换药服务，包括检查伤口、清洁伤口、包扎及更换敷料等。");
        serviceIntro.setContent("打针:由东华数字医院专业护士为需要皮下或肌肉注射的患者提供的上门打针的护理服务，不提供相关药物。\n" +
                "普通换药:由东华数字医院专业护士提供普通伤口或术后的换药服务，包括检查伤口、清洁伤口、包扎及更换敷料等。");

        retExplain.setServiceIntro(serviceIntro);

        WarmTips warmTips = new WarmTips();
        warmTips.setContent(new ArrayList<String>());
        warmTips.getContent().add("打针");
        warmTips.getContent().add("本服务为皮下注射和肌肉注射，不提供静脉输液服务；");
        warmTips.getContent().add("预约本服务，需提供经由正规医疗机构开具的医嘱、处方等文件上传平台：");
        warmTips.getContent().add("本服务相关耗材需从平台购买，如自卑耗材，需提供经由正规渠道购买的收据或发票等文件上传凭条，因自备耗材存在的任何质量问题，均与平台无关；");
        warmTips.getContent().add("请确认患者对使用药物无过敏现象；");
        warmTips.getContent().add("同一地址一次上门服务仅服务一人；");
        warmTips.getContent().add("普通换药");
        warmTips.getContent().add("本服务只提供换药技术服务，不提供相关药品；");
        warmTips.getContent().add("预约本服务，需提供经由正规医疗机构开具的医嘱、处方等文件上传平台；");
        warmTips.getContent().add("本服务相关耗材需从平台购买，如自备耗材，需提供经由正规渠道购买的收据或发票等文件上传凭条，因自备耗材存在的任何质量问题，均与平台无关；");
        warmTips.getContent().add("伤口严重感染或坏死、大量活动性出血者不提供上门换药服务；");
        warmTips.getContent().add("同一地址一次上门服务仅服务一人；");
        retExplain.setWarmTips(warmTips);

        retExplain.setFeeList(new ArrayList<FeeList>());
        FeeList feeList = new FeeList();
        feeList.setItem("打针");
        feeList.setPrice("192.89");
        feeList.setRemark("测试，此处为对应项目的价格备注/说明");
        retExplain.getFeeList().add(feeList);

        feeList = new FeeList();
        feeList.setItem("上门换药");
        feeList.setPrice("129.99");
        feeList.setRemark("测试，此处为对应项目的价格备注/说明");
        retExplain.getFeeList().add(feeList);

        feeList = new FeeList();
        feeList.setItem("项目名称");
        feeList.setPrice("199.99");
        feeList.setRemark("测试，此处为对应项目的价格备注/说明");
        retExplain.getFeeList().add(feeList);


        RefundRules refundRules = new RefundRules();
        refundRules.setContent(new ArrayList<String>());

        ServiceRule rule = new ServiceRule();
        rule.setRuleType("1");
        rule.setRuleDelFlag("0");
        rule.setRuleUseFlag("0");
        Double refundBit = 1.0;
        DecimalFormat df = new DecimalFormat("0.00%"); // 保留两位小数
        List<ServiceRule> ruleVOList = ruleMapper.selectServiceRuleList(rule);
        for (ServiceRule serviceRule : ruleVOList){
            Double ruleRefund = (refundBit - serviceRule.getRuleRefund());
            String percentage = df.format(ruleRefund);
            ServiceFlag flag = flagMapper.selectServiceFlagByFlagCode(String.valueOf(serviceRule.getRuleFlag()));
            if (flag != null){
                refundRules.getContent().add("订单状态：" + flag.getFlagDesc() + "-扣除费用比率比率：" + percentage );
            }

        }

        //refundRules.getContent().add("单次服务：护士已接单未出发，不扣费。");
        //refundRules.getContent().add("单次服务：护士已出发未服务，扣除预付服务费的60%，预付车程费100%。");
        //refundRules.getContent().add("多次服务：护士已接单未出发，扣除预付金额除以总服务次数的30%(已服务过的项目，正常结算)。");
        //refundRules.getContent().add("多次服务：护士已出发未服务，扣除预付金额除以总服务次数的60%(已服务过的项目，正常结算)。");
        retExplain.setRefundRules(refundRules);

        retExplain.setStepsList(new ArrayList<StepsList>());
        StepsList stepsList = new StepsList();
        stepsList.setTitle("预约服务");
        stepsList.setDesc("提交订单");
        retExplain.getStepsList().add(stepsList);

        stepsList = new StepsList();
        stepsList.setTitle("护理服务组");
        stepsList.setDesc("审核派单");
        retExplain.getStepsList().add(stepsList);

        stepsList = new StepsList();
        stepsList.setTitle("护士接单");
        stepsList.setDesc("护士已接单");
        retExplain.getStepsList().add(stepsList);

        stepsList = new StepsList();
        stepsList.setTitle("护士出发");
        stepsList.setDesc("即将上门服务");
        retExplain.getStepsList().add(stepsList);

        stepsList = new StepsList();
        stepsList.setTitle("核实费用");
        stepsList.setDesc("(耗材/车程费)");
        retExplain.getStepsList().add(stepsList);

        stepsList = new StepsList();
        stepsList.setTitle("最终结箅");
        stepsList.setDesc("(退款/补差价)");
        retExplain.getStepsList().add(stepsList);

        stepsList = new StepsList();
        stepsList.setTitle("订单完成");
        stepsList.setDesc("订单已完成");
        retExplain.getStepsList().add(stepsList);

        Disclaimer disclaimer = new Disclaimer();
        disclaimer.setContent(new ArrayList<String>());
        disclaimer.getContent().add("服务费-预付费-预付费后方可生成订单");
        disclaimer.getContent().add("耗材费-预付费-从平台购买，则需预付费后方可生成订单，最终以实际使用耗材情况进行结算");
        disclaimer.getContent().add("车程费-预付费-预付费为医院与预约地点往返的估算车程费，最终以实际产生车程费用情况结算");
        retExplain.setDisclaimer(disclaimer);

        return retExplain;
    }
}
